package com.gzsxy.esjy.service.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gzsxy.esjy.bus.log.annotation.OperLog;
import com.gzsxy.esjy.bus.log.enum1.LogActionType;
import com.gzsxy.esjy.service.base.dto.request.CommentRequest;
import com.gzsxy.esjy.service.base.dto.response.CommentRsp;
import com.gzsxy.esjy.service.base.dto.response.DefaultResponse;
import com.gzsxy.esjy.service.base.util.Page;
import com.gzsxy.esjy.service.product.entity.vo.CommentQueryVo;
import com.gzsxy.esjy.service.product.service.CommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @author xiaolong
 * @version 1.0
 * @description: 商品评论
 * @date 2022/2/11 9:03
 */
@CrossOrigin  //解决跨域
@RefreshScope    //动态刷新配置文件-外部配置文件
@RestController
@RequestMapping("/admin/product/comment")
@Api("商品评论管理")
public class CommentController {

    @Autowired
    private CommentService commentService;


    @GetMapping("/list")
    @ApiOperation("分页查询")
    public DefaultResponse page(Page<?> page, CommentQueryVo commentQueryVo, HttpServletRequest request){
        IPage<CommentRsp> list = commentService.getPageVo(page,commentQueryVo);
       return DefaultResponse.ok(list);
    }


    @PutMapping("/reply")
    @ApiOperation("回复评论")
    @OperLog(operModul = "商品评论管理",operType = LogActionType.UPDATE,operDesc = "回复评论")
    public DefaultResponse replyComment(@RequestBody CommentRequest commentRequest){
        commentService.replyComment(commentRequest);
        return DefaultResponse.ok();
    }

    @ApiOperation("删除评论")
    @DeleteMapping("/delete/{id}")
    @OperLog(operModul = "商品评论管理",operType = LogActionType.DELETE,operDesc = "删除评论")
    public DefaultResponse deleteComment(@PathVariable String id){
        commentService.deleteComment(id);
        return DefaultResponse.ok();
    }
}
